package org.dromara.resource.api.feign.fallback;

import cn.hutool.http.HttpStatus;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.resource.api.feign.ResourceFileClient;
import org.dromara.resource.api.domain.RemoteFile;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author: zhou shuai
 * @date: 2024/10/5 15:36
 * @version: v1
 */
@Slf4j
@Component
public class ResourceFileFallBack implements FallbackFactory<ResourceFileClient> {

    @Override
    public ResourceFileClient create(Throwable throwable) {
        log.error("ResourceFileFallBack, cause:{}", throwable.getMessage());
        return new ResourceFileClient() {

            @Override
            public R<RemoteFile> fileUpload(MultipartFile avatarfile) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<String> getFileUrlByOssIds(String ossIds) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<List<RemoteFile>> getFileListByOssIds(String ossIds) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }
        };
    }

}
